package io.renren.modules.store.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.annotation.NoRepeatSubmit;
import io.renren.common.exception.RRException;
import io.renren.common.utils.BeanJudgeUtil;
import io.renren.modules.store.entity.TStoreStaffCommissionTypeEntity;
import io.renren.modules.store.service.TStoreStaffCommissionTypeService;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author steakliu
 * @email 2319492349@qq.com
 * @date 2021-01-28 22:44:15
 */
@RestController
@RequestMapping("member/tstorestaffcommissiontype")
public class TStoreStaffCommissionTypeController extends AbstractController {
    @Autowired
    private TStoreStaffCommissionTypeService tStoreStaffCommissionTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("member:tstorestaffcommissiontype:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("sellerId",getSeller());
        PageUtils page = tStoreStaffCommissionTypeService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("member:tstorestaffcommissiontype:info")
    public R info(@PathVariable("id") Long id){
		TStoreStaffCommissionTypeEntity tStoreStaffCommissionType = tStoreStaffCommissionTypeService.getById(id);
        return R.ok().put("tStoreStaffCommissionType", tStoreStaffCommissionType);
    }

    /**
     * 保存
     */
    @NoRepeatSubmit
    @RequestMapping("/save")
    @RequiresPermissions("member:tstorestaffcommissiontype:save")
    public R save(@RequestBody TStoreStaffCommissionTypeEntity tStoreStaffCommissionType){
        TStoreStaffCommissionTypeEntity one = tStoreStaffCommissionTypeService.getOne(new QueryWrapper<TStoreStaffCommissionTypeEntity>()
                .eq("seller_id", getSeller())
                .eq("commission_type_name", tStoreStaffCommissionType.getCommissionTypeName())
        );
        if (!BeanJudgeUtil.beanIsNull(one)){
            throw new RRException("提成名称已存在，请重新设置");
        }
        tStoreStaffCommissionType.setSellerId(getSeller());
		tStoreStaffCommissionTypeService.save(tStoreStaffCommissionType);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member:tstorestaffcommissiontype:update")
    public R update(@RequestBody TStoreStaffCommissionTypeEntity tStoreStaffCommissionType){
		tStoreStaffCommissionTypeService.updateById(tStoreStaffCommissionType);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("member:tstorestaffcommissiontype:delete")
    public R delete(@RequestBody Long[] ids){
		tStoreStaffCommissionTypeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
